//package com.java.zhuiyun.api.video_manage.aspectj;
//
//import cn.hutool.http.useragent.UserAgent;
//import cn.hutool.http.useragent.UserAgentUtil;
//import cn.hutool.log.Log;
//import com.java.zhuiyun.util.MapUtils;
//import lombok.extern.slf4j.Slf4j;
//import lombok.var;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import java.lang.reflect.Method;
//import java.util.Map;
//
///**
// * @ClassName OperationLogAspect
// * @Description TODO
// * @Author MJL
// * @Date 2023/8/25 11:13
// **/
//@Slf4j
//@Aspect
//@Component
//public class OperationLogAspect {
//    @Resource
//    HttpServletRequest httpServletRequest;
//
//    private static final Logger log = LoggerFactory.getLogger(OperationLogAspect.class)
//    /**
//    * @Author MJL
//    * @Description todo 设置操作日志切入点，在注解的位置切入代码
//    * @Date 2023/8/25 11:14
//    * @Return  * @param null
//    */
//    @Pointcut("@annotation(com.java.zhuiyun.api.video_manage.aspectj.OprLog)")
//    public void oprLogPointCut(){
//
//    }
//    /**
//    * @Author MJL
//    * @Description todo 环绕切点
//    * @Date 2023/8/25 14:30
//    * @Return  * @param null
//    */
//    @Around("oprLogPointCut()")
//    public Object log(ProceedingJoinPoint pjp) throws Throwable{
//        long beginTime = System.currentTimeMillis();
//        // 执行切点方法
//        Object result = pjp.proceed();
//        // 执行时长
//        Long runTime = System.currentTimeMillis() - beginTime;
//        // 记录日志
//        handleLog(pjp,runTime);
//        return result;
//    }
//
//    private void handleLog(ProceedingJoinPoint pjp,Long runTime){
//        MethodSignature signature = (MethodSignature) pjp.getSignature();
//        Method method = signature.getMethod();
//        // 获取注解内容
//        var logAnnotation = method.getAnnotation(Log.class);
//        // 获取模块；
//        String title = logAnnotation.title();
//        // 获取业务类型
//        BusinessType businessType = logAnnotation.businessType;
//    }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
////    /**
////    * @Author MJL
////    * @Description todo 记录操作日志
////    * @Date 2023/8/25 11:16
////    * @Return  * @param null
////    */
////    @AfterReturning(returning = "result", value = "oprLogPointCut()")
////    public void saveOperLog(JoinPoint joinPoint, Object result){
////        try {
////            // 获得注解
////            OprLog controllerLog = getAnnotationLog(joinPoint);
////            if (controllerLog == null){
////                return;
////            }
////            // 将返回值转换成map集合
////            Map<String, String> map = (Map<String, String>) result;
////            // 返回值信息
////            String msg = MapUtils.getString(map, "msg");
////            UserAgentUtil userAgentUtil = UserAgentUtil.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
////            // 获取客户端操作系统
////            String os = userAgent.getOperatingSystem().getName();
////            // 获取客户端浏览器
////            String browser = userAgent.getBrowser().getName();
////            // 获取用户信息
////            IotMSUser user = TokenUtil.getUserId();
////            // 用户ID,"-1" 代表没有登陆系统用户
////            Integer userId=-1;
////            if (!ObjectUtils.isEmpty(user)){
////                userId=user.getId();
////            }
////            // 获取Ip地址
////            String ipAddress = IpUtils.getIpAddress();
////            com.kl.entity.OprLog oprLog = new com.kl.entity.OprLog();
////            oprLog.setIp(ipAddress);
////            oprLog.setUserAgent(browser);
////            oprLog.setUserId(userId);
////            oprLog.setContent(controllerLog.content());
////            oprLog.setCreateTime(FormatUtil.formatDate());
////            OprLogRepo oprLogRepo = SpringUtils.getBean(OprLogRepo.class);
////            oprLogRepo.save(oprLog);
////        }catch (Exception e){
////            // 记录本地异常日志
////            log.error("==前置通知异常==");
////            log.error("异常信息:{}", e.getMessage());
////        }
////    }
////    /**
////    * @Author MJL
////    * @Description todo 检查是否存在注解，如果存在就获取
////    * @Date 2023/8/25 13:58
////    * @Return  * @param null
////    */
////    private OprLog getAnnotationLog(JoinPoint joinPoint) throws Exception{
////        Signature signature = joinPoint.getSignature();
////        MethodSignature methodSignature = (MethodSignature) signature;
////        Method method = methodSignature.getMethod();
////        if (method != null){
////            return method.getAnnotation(OprLog.class);
////        }
////        return null;
////    }
//}
